// pages/department-select-followup/department-select-followup.js
Page({
	data: {
		selectedCampus: '湘南院区',
		selectedDepartment: '内科',
		isLoading: false,
		patientName: '',
		subDepartments: [
			'呼吸内科',
			'消化内科',
			'心血管内科',
			'血液内科',
			'肾内科'
		]
	},

	onLoad(options) {
		console.log('复诊配药 - 医院科室选择页面加载')
		console.log('页面参数:', options)
		
		if (options.patient) {
			this.setData({
				patientName: options.patient
			})
		}
	},

	selectDepartment(e) {
		const department = e.currentTarget.dataset.department
		const campus = this.data.selectedCampus
		console.log('复诊配药 - 选择了科室:', department, '当前院区:', campus)
		
		// 根据选择的科室和当前院区更新子科室列表
		let subDepartments = []
		
		switch(department) {
			case '内科':
				subDepartments = [
					'呼吸内科',
					'消化内科',
					'心血管内科',
					'血液内科',
					'肾内科'
				]
				break
			case '外科':
				subDepartments = [
					'肝胆脾外科',
					'心胸外科',
					'泌尿外科',
					'神经外科',
					'烧伤外科'
				]
				break
			case '儿科':
				subDepartments = [
					'呼吸科',
					'消化科',
					'神经科',
					'血液科',
					'心血管科'
				]
				break
			case '神经内科':
				subDepartments = [
					'脑血管病专科',
					'癫痫与睡眠障碍专科',
					'神经肌肉病专科',
					'头痛与神经痛专科',
					'认知障碍与痴呆专科'
				]
				break
			case '耳鼻喉科':
				subDepartments = [
					'耳显微外科',
					'耳神经外科',
					'喉显微外科',
					'鼻内镜外科',
					'鼻神经外科'
				]
				break
			case '眼科门诊':
				subDepartments = [
					'普通眼科门诊',
					'白内障专科门诊',
					'青光眼专科门诊',
					'眼外伤专科门诊',
					'眼底病专科门诊'
				]
				break
			case '皮肤科':
				subDepartments = [
					'普通皮肤科',
					'皮肤外科',
					'小儿皮肤科',
					'皮肤美容专科',
					'色素性皮肤病专科'
				]
				break
			case '心理科':
				subDepartments = [
					'普通心理科',
					'精神科',
					'心理咨询与治疗科',
					'儿童青少年心理科',
					'睡眠障碍专科'
				]
				break
			case '营养科':
				subDepartments = [
					'临床营养科',
					'营养咨询科',
					'营养治疗科',
					'营养评估科',
					'营养教育科'
				]
				break
			case '全科门诊':
				subDepartments = [
					'全科医学科',
					'家庭医学科',
					'社区医学科',
					'预防保健科',
					'健康管理科'
				]
				break
			case '麻醉科':
				subDepartments = [
					'麻醉科',
					'疼痛科',
					'重症医学科',
					'麻醉恢复室',
					'麻醉门诊'
				]
				break
			case '康复中心':
				subDepartments = [
					'物理治疗科',
					'作业治疗科',
					'言语治疗科',
					'康复评定科',
					'康复工程科'
				]
				break
			case '疼痛科':
				subDepartments = [
					'慢性疼痛科',
					'急性疼痛科',
					'神经痛科',
					'癌痛科',
					'疼痛康复科'
				]
				break
			default:
				subDepartments = ['暂无子科室']
		}
		
		this.setData({
			selectedDepartment: department,
			subDepartments: subDepartments
		})
	},

	selectCampus(e) {
		const campus = e.currentTarget.dataset.campus
		console.log('复诊配药 - 选择了院区:', campus)
		
		this.setData({
			selectedCampus: campus
		})
		
		// 这里可以根据院区重新加载科室数据
		// 目前使用相同的科室数据
	},

	selectSubDepartment(e) {
		const subDepartment = e.currentTarget.dataset.subDepartment
		const department = this.data.selectedDepartment
		const campus = this.data.selectedCampus
		
		console.log('复诊配药 - 选择了子科室:', subDepartment, '科室:', department, '院区:', campus)
		
		// 用户端逻辑：选择科室后直接跳转到“选择处方配药”页面
		wx.navigateTo({
			url: '/pages/prescription-select/prescription-select?patient=' + (this.data.patientName || '') + '&department=' + department + '&subDepartment=' + subDepartment + '&campus=' + campus
		})
	}
})
